package com.letoy.edu.service.Impl;

import com.letoy.edu.dao.MajorInfoMapper;
import com.letoy.edu.entity.MajorInfo;
import com.letoy.edu.service.MajorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class MajorInfoServiceImpl implements MajorInfoService {

    @Autowired
    MajorInfoMapper majorInfoMapper;

    @Override
    public HashMap<String, Object> insertMajorInfo(MajorInfo majorInfo) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = majorInfoMapper.insertMajorInfo(majorInfo);

        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "新增失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "新增成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> deleteMajorInfo(int majorId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = majorInfoMapper.deleteMajorInfo(majorId);
        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "删除失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "删除成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> updateMajorInfo(MajorInfo majorInfo) {
        HashMap<String, Object> hashMap = new HashMap<>();
        int result = majorInfoMapper.updateMajorInfo(majorInfo);
        if (result == 0) {
            hashMap.put("status", "1");
            hashMap.put("msg", "更新失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("msg", "更新成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> getMajorInfoByMajorId(int majorId) {
        HashMap<String, Object> hashMap = new HashMap<>();
        MajorInfo majorInfoByMajorId = majorInfoMapper.getMajorInfoByMajorId(majorId);
        if (majorInfoByMajorId == null) {
            hashMap.put("status", "1");
            hashMap.put("msg", "查询失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("data", majorInfoByMajorId);
        hashMap.put("msg", "查询成功");
        return hashMap;
    }

    @Override
    public HashMap<String, Object> getAllMajorInfo() {
        HashMap<String, Object> hashMap = new HashMap<>();
        List<MajorInfo> allMajorInfo = majorInfoMapper.getAllMajorInfo();
        if (allMajorInfo.isEmpty()) {
            hashMap.put("status", "1");
            hashMap.put("msg", "查询失败");
            return hashMap;
        }
        hashMap.put("status", "0");
        hashMap.put("data", allMajorInfo);
        hashMap.put("msg", "查询成功");
        return hashMap;
    }
}
